package com.bqnxzz.ywiigame.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class ManifestUtil {
    public static String channel = null;
    public static String installSource = null;

    public static String getChannel(Context context) {
        try {
            if(channel == null) {
                ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
                channel = info.metaData.getString("CHANNEL_CODE");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return channel;
    }

    public static int getVersionCode(Context context)//获取版本号(内部识别号)
    {
        try {
            PackageInfo pi=context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static String getInstallsource(Context context) {
        try {
            if(installSource == null) {
                ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
                installSource = Integer.toString(info.metaData.getInt("INSTALL_SOURCE"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return installSource;
    }
}
